package com.cpi.cornpp.costelement.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.MappingDispatchAction;

import com.cpi.cornpp.costelement.view.CostElementView;
import com.cpi.cornpp.transports.exception.TransportException;

public class ShowAddNewCostElementAction extends MappingDispatchAction {
	private static final String SUCCESS_FORWARD = "toSuccess";
	private static final String FAILURE_FORWARD = "error";
	
	public ActionForward createNewCostElement(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws TransportException {
		CostElementView costElementView = null;
		HttpSession session = null;
		ActionForward forward = null;
		
		forward = mapping.findForward(FAILURE_FORWARD);
		session = request.getSession(false);
		
		costElementView = new CostElementView();
		
		session.removeAttribute("addedCostElementTransport");
		
		session.setAttribute("costElementView", costElementView);
		request.setAttribute("costElementView", costElementView);
		
		forward = mapping.findForward(SUCCESS_FORWARD);
		
		return forward;
	}
}